<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>卖家中心</title>
    <!--获取屏幕宽度，根据屏幕宽度进行自适应-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--引入Bootstrap-->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!--自定义工具-->
    <script src="js/HttpUtil.js"></script>
    <!--导入vue 包-->
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>


    <style>
        a:hover {
            color: #cc3333;
            text-decoration: none;
        }

        a {
            color: black;
            cursor: pointer;
        }
    </style>
</head>

<body>

<div class="container-fluid" style="margin-top: 1%">
    <!-- 头信息 -->
    <header>
        <div class="col-xs-offset-1">
            <img src="../shop/images/logo.png">
        </div>
        <hr>
        <div class="row" style="background-color: #A4D3EE">
            <div class="col-xs-2 col-lg-offset-1">
                <h3>GitBug 商城订单管理</h3>
            </div>
        </div>
    </header>


    <div class="row">
        <div class="col-xs-1 col-lg-offset-1" style="background-color:#F7F7F7; height: 800px; position: absolute">
            <h4 style="padding:50% 0 10% 20%"><a href="home_admin.html">个人中心</a></h4>
            <h4 style="padding:10% 0 10% 20%"><a href="goods-manage.html">商品管理</a></h4>
            <h4 style="padding:10% 0 10% 20%"><a href="orderItems_admin.html">订单管理</a></h4>
        </div>
        <div class="col-lg-offset-2 " style="margin-top: 1%">
        <h3>个人中心&nbsp>&nbsp订单管理</h3>
        <hr>
    </div>

        <!-- 订单列表展示  -->
        <div class=" col-md-8 col-lg-offset-2" id="order_vue">
            下单时间：
            <input type="date" id="datetime1">-
            <input type="date" id="datetime2">
            <input type="button" value="搜索" @click="searchByDate()">

            <table class="table table-striped table-bordered table-hover" style="margin-top: 1%">
                <thead>
                <tr class="success">
                    <th>订单ID</th>
                    <th>状态</th>
                    <th>金额</th>
                    <th>商品数量</th>
                    <th>买家ID</th>
                    <th>下单时间</th>
                    <th>发货时间</th>
                    <th>取消时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="order in orderList">
                    <td>{{order.id}}</td>
                    <td>{{order.status}}</td>
                    <td>￥&nbsp{{order.amount}}</td>
                    <td>{{order.quantity}}</td>
                    <td>{{order.uid}}</td>
                    <td>{{order.createDate}}</td>
                    <td>{{order.deliveryDate}}</td>
                    <td>{{order.cancelDate}}</td>
                    <td class="inputButton">
                        <input type="button" class="btn btn-primary" :id="order.id" @click="viewDetail(order)"
                               value="产看详细">
                        <input type="button" class="btn btn-success " :id="order.deliveryDate" @click="sendOrder(order)"
                               value="发货">
                        <input type="button" class="btn btn-warning " :id="order.cancelDate" @click="cancelOrder(order)"
                               value="取消">
                    </td>
                </tr>

                <tr id="goodsDetail">
                    <td colspan="9">
                        <table>
                            <tr v-for="goodsDetail in goodsDetailList" style="text-align: center">
                                <div :class="goodsDetail.number"></div>
                                <td class="col-md-2"><img :src="goodsDetail.imageUrl" style="height: 100px"></td>
                                <td class="col-md-3">{{goodsDetail.name}}</td>
                                <td class="col-md-1">{{goodsDetail.number}}个</td>
                                <td class="col-md-1">单价：￥{{goodsDetail.price}}</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                </tbody>
            </table>

        </div>
    </div>
</div>


<!-- 页脚信息 -->

<div class="container-fluid" style="background-color: ghostwhite; margin-top: 5%; ">
    <div class="row" style="margin-top: 2%;margin-bottom: 5%">
        <div class="col-xs-1 col-xs-offset-2">
            <p style="">视频中心</p>
            <a>
                <div style="padding-top: 10%">新闻发布会</div>
            </a>
            <a>
                <div style="padding-top: 5%">发展历程</div>
            </a>
            <a>
                <div style="padding-top: 5%">直播</div>
            </a>
            <a>
                <div style="padding-top: 5%">员工视频</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <p style="">发现</p>
            <a>
                <div style="padding-top: 10%">成功故事</div>
            </a>
            <a>
                <div style="padding-top: 5%">公司年报</div>
            </a>
            <a>
                <div style="padding-top: 5%">管理层信息</div>
            </a>
            <a>
                <div style="padding-top: 5%">媒体图库</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <p style="">关注我们</p>
            <a>
                <div style="padding-top: 10%">新浪微博</div>
            </a>
            <a>
                <div style="padding-top: 5%">微信公众号</div>
            </a>
            <a>
                <div style="padding-top: 5%">优酷视频</div>
            </a>
            <a>
                <div style="padding-top: 5%">哔哩哔哩</div>
            </a>
        </div>
        <div class="col-xs-1 ">
            <a href="http://localhost:8080/views/shop/home2.html">商城主页</a>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">


    let vue = new Vue({
        el: '#order_vue',
        data: {
            orderList: "",
            goodsDetailList: "",
        },

        methods: {
            //根据日期获取订单，默认未全部获取
            searchByDate: function () {
                let url = "selectOrderByDate"
                let beforeDate = document.getElementById("datetime1").value;
                let afterDate = document.getElementById("datetime2").value;
                let params = {beforeDate, afterDate};
                let thisObject = this;
                postWithJson(url, params, function (data) {
                    thisObject.orderList = data;
                    thisObject.goodsDetailList = "";
                    thisObject.refreshButton()
                })
                console.log(localStorage.getItem("seller"));
            },

            //按钮隐藏
            refreshButton: function () {
                let url = "selectOrderByDate"
                let beforeDate = document.getElementById("datetime1").value;
                let afterDate = document.getElementById("datetime2").value;
                let params = {beforeDate, afterDate};
                let thisObject = this;
                postWithJson(url, params, function (data) {
                    data.forEach(item => {
                        let deliveryDate = item.deliveryDate;
                        let cancelDate = item.cancelDate;
                        //点击发货按钮，隐藏发货按钮
                        if (deliveryDate) {
                            document.getElementById(deliveryDate).style.display = "none";
                        }
                        //点击取消按钮，隐藏取消按钮和发货按钮
                        if (cancelDate) {
                            document.getElementById(cancelDate).setAttribute("style", "display:none");
                            document.getElementById(cancelDate).previousElementSibling.setAttribute("style", "display:none")
                        }
                    });
                });
            },

            //点击发货事件
            sendOrder: function (order) {
                let url = "sendOrder";
                let thisObject = this;
                postWithJson(url, order, function () {
                    thisObject.searchByDate();
                });
            },

            //点击取消事件
            cancelOrder: function (order) {
                let url = "cancelOrder";
                let thisObject = this;
                postWithJson(url, order, function () {
                    thisObject.searchByDate()

                })
            },

            //点击查看详细事件
            viewDetail: function (order) {
                let url = "orderDetail";
                let thisObject = this;
                postWithJson(url, order, function (data) {
                    thisObject.goodsDetailList = data;
                    let id = order.id;
                    let parent = $("#" + id).parent().parent();
                    let goodsDetail = $("#goodsDetail");
                    parent.after(goodsDetail);
                })
            },
        },

        mounted: function () {
            //页面加载完成，并且vue对象加载完成之后调用
            this.searchByDate();
        },
    });


</script>
